package org.example.cet.demos.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.dto.SwiperDto;
import org.example.cet.demos.domain.po.Swiper;
import org.example.cet.demos.domain.query.SwiperQuery;
import org.example.cet.demos.mapper.SwiperMapper;
import org.example.cet.demos.service.ISwiperService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@Service
@RequiredArgsConstructor

public class SwiperServiceImpl extends ServiceImpl<SwiperMapper, Swiper> implements ISwiperService {

    public PageBean getPage(SwiperQuery swiperQuery) {
        Page<Swiper> page = new Page<>(swiperQuery.getCurrentPage(), swiperQuery.getPageSize());
        lambdaQuery().like(swiperQuery.getId()!=null, Swiper::getId, swiperQuery.getId())
                .like(!StrUtil.isBlankIfStr(swiperQuery.getTitle()), Swiper::getTitle, swiperQuery.getTitle())
                .like(!StrUtil.isBlankIfStr(swiperQuery.getUpdateBy()), Swiper::getUpdateBy, swiperQuery.getUpdateBy())
                .like(!StrUtil.isBlankIfStr(swiperQuery.getCreateBy()), Swiper::getCreateBy, swiperQuery.getCreateBy())
                .page(page);
        PageBean pageBean = new PageBean();
        pageBean.setTotal(page.getTotal());
        pageBean.setRows(page.getRecords());
        return pageBean;
    }

    @Autowired
    private SwiperMapper swiperMapper;
    @Override
    public List<SwiperDto> getList(){
        return swiperMapper.getList();
    }
}
